package com.i2863.receipt.dto;

import com.i2863.receipt.entity.Prize;
import lombok.Data;

import javax.persistence.Column;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * @author xuweiwei
 * @date 2018/6/15
 */
@Data
public class SinglePrize implements Comparable<SinglePrize> {
    private BigDecimal money;
    private Integer level;
    private String levelName;
    private Integer prize;
    private String prizeName;

    public static  List<SinglePrize> valueOf(List<Prize> prizeList){
        List<SinglePrize> singlePrizeList = new ArrayList(prizeList.size()*3);
        for(Prize p:prizeList){
            for(int i=0;i<p.getNumber();i++){
                SinglePrize singlePrize = new SinglePrize();
                singlePrize.setMoney(p.getMoney());
                singlePrize.setLevel(p.getLevel());
                singlePrize.setLevelName(p.getName());
                singlePrize.setPrize(p.getPrize());
                singlePrize.setPrizeName(p.getPrizeName());
                singlePrizeList.add(singlePrize);
            }
        }
        return singlePrizeList;
    }

    public static void main(String[] args) {
        List<Prize> prizes  = new ArrayList<Prize>();
        Prize prize1 = new Prize();
        prize1.setLevel(0);
        prize1.setMoney(new BigDecimal(100000));
        prize1.setName("特等奖");
        prize1.setNumber(1);
        prizes.add(prize1);
        Prize prize2 = new Prize();
        prize2.setLevel(1);
        prize2.setMoney(new BigDecimal(10000));
        prize2.setName("一等奖");
        prize2.setNumber(3);
        prizes.add(prize2);
        List<SinglePrize> singlePrizeList = valueOf(prizes);
        System.out.println(singlePrizeList.size());
    }


    @Override
    public int compareTo(SinglePrize o) {
        return Integer.valueOf(getLevel()*100+getPrize()).compareTo(o.getLevel()*100+o.getPrize());
    }
}
